import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-11-19
 * Time: 22:22
 */
class Trie {
    Map<String, List<String>> hash;
    // key字符串 value 以key为前缀的字符串
    public Trie() {
        hash = new HashMap<>();
    }

    public void insert(String word) {
        hash.put(word,new ArrayList<>());
        for(String key : hash.keySet()) {
            if(key.startsWith(word)) {
                hash.get(word).addAll(hash.get(key));
            }
        }
    }
    public boolean search(String word) {
        return hash.containsKey(word);
    }

    public boolean startsWith(String prefix) {
        for(String key : hash.keySet()) {
            if(key.startsWith(prefix)) {
                return true;
            }
        }
        return false;
    }
}
